<?php

class LogController extends Sgit_Controller_Action
{
    protected $_checkAcceso = true;
    protected $_checkZona = false;


    public function indexAction()
    {
        
     
        $this->_helper->viewRenderer->setNoRender(TRUE);
        
        
        $file=$this->_getParam('fecha',date('Ymd').'log');
        $log=APPLICATION_PATH."/logs/$file.txt";


        print '<script type="text/javascript" src="http://balupton.github.com/jquery-syntaxhighlighter/scripts/jquery.syntaxhighlighter.min.js"></script><script type="text/javascript">$.SyntaxHighlighter.init({\'lineNumbers\': false,\'wrapLines\': true});</script>';


         print date('Y-m-d H:i:s');
        $table="<table class='tablesorter'>";
        $table.="<tr>
        <th class='ui-state-active'></th>
        <th class='ui-state-active'>ElapsedSecs</th>
        <th class='ui-state-active'>Controller</th>
        <th class='ui-state-active'>Usuario</th>
        <th class='ui-state-active'>Query</th></tr>";
       

        $gestor = fopen($log, "r");
        
        $i=0;
        while ($userinfo = fgets($gestor,1024)) {

           $fila=explode('||',$userinfo); 
           $fila[0]=explode(' ',$fila[0]);

           $tabl[]="<tr class='ui-state-highlight'><td>".date('Y-m-d H:i:s',strtotime($fila[0][0]))."</td><td>".round($fila[1],6)."</td><td>".$fila[2]."</td><td>".$fila[3]."</td><td><pre class='highlight'>".$fila[4]."</pre></td></tr>";

        }
        fclose($gestor);
        
        
        //$table.="<tr class='ui-state-highlight' ><td>T</td><td>".round($profiler->getTotalElapsedSecs(),6)."</td><td colspan=2></td></tr>";
       
        for($k=0;$k<300;$k++)
        {
            $table.=$tabl[count($tabl)-$k];
        }
        $table.="</table>";
        
        
        print $table;
        
    
    }





  



}
